package com.ecnu.web.controller.project;

import com.ecnu.common.core.controller.BaseController;
import com.ecnu.common.core.domain.AjaxResult;
import com.ecnu.common.core.domain.model.LoginUser;
import com.ecnu.system.domain.dto.SpectrumDTO;
import com.ecnu.system.service.ISpectrumService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import javax.validation.constraints.NotBlank;
import java.util.Map;

@Api(tags = "图谱公共接口")
@RestController
@RequestMapping("/spectrum")
public class SpectrumController extends BaseController {
    @Autowired
    private ISpectrumService spectrumService;
    /**
     * 图谱整体数据（按照key，value方式模块提供）
     * @return
     */
    @GetMapping("/list")
    @ApiOperation(value = "图谱表")
    public AjaxResult list(@RequestParam @NotBlank(message = "项目id不能为空") String proId) {
        LoginUser loginUser = getLoginUser();
        return spectrumService.list(proId,loginUser);
    }

    /**
     * 获取路径点信息
     * @return
     */
    @GetMapping("/getInfo")
    @ApiOperation(value = "获取路径点信息")
    public AjaxResult getInfo(@RequestParam
                                  @NotBlank String proId,
                              Integer id,
                              String type //1、关键路径；2、核心知识
    ) {
        LoginUser loginUser = getLoginUser();
        return spectrumService.infoByLinke(proId, id, type);
    }

    @GetMapping("/getMatrixInfo")
    @ApiOperation(value = "获取路径点信息")
    public AjaxResult getMatrixInfo(@RequestParam
                              @NotBlank String proId
    ) {
        LoginUser loginUser = getLoginUser();
        return spectrumService.getMatrixInfo(proId);
    }

    /**
     * 图谱编辑保存
     * @return
     */
    @PostMapping("/edit")
    @ApiOperation(value = "保存")
    public AjaxResult edit(@Valid @RequestBody SpectrumDTO data) {
        return spectrumService.insert(data);
    }

    /**
     * 获取需求列表
     * @return
     */
    @GetMapping("/info")
    @ApiOperation(value = "根据需求提供内容")
    public AjaxResult info(@RequestParam @NotBlank(message = "项目id不能为空")String proId
            ,@RequestParam @NotBlank(message = "项目id不能为空") String name) {
        return spectrumService.infoByOne(proId, name);
    }
}
